#include<stdio.h>
#include"core.h"
#include"ram.h"
#include"putchar.h"

// 内核
struct riscv_Core *RISCV = NULL;

void VM_init(){
    RISCV = core_init();
    if(RISCV == NULL){
        printf("初始化失败\r\n");
        return;
    }
    dev_register(RISCV->devices,&ram_dev);
    dev_register(RISCV->devices,&putchar_dev);
}

void VM_run(){
    if(RISCV == NULL){
        printf("核心未初始化\r\n");
        return;
    }
    while(1){
        run_inst(RISCV);
    }
}

void load_program(uint8_t *program,uint32_t start_addr, uint32_t size){
    for(int i = 0; i < size; i++){
        dev_write_b(RISCV->devices,(i)+ start_addr, program[i]);
    }
}